<?php

namespace App\Console\Commands;

use App\Jobs\CheckOrderRecord;
use App\Jobs\VisitRecord;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class GetRedisCheckOrderData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'get:redis_check_order_data {date?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '获取redis检测订单访问数据';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $redis = Redis::connection();
        $date = $this->argument('date') ?: Carbon::now()->toDateString();

        $num = $redis->llen('check_order_record:'.$date);
        for ($i = 0; $i < $num; $i++) {
            $check_order_info = $redis->lpop('check_order_record:'.$date);
            CheckOrderRecord::dispatch($check_order_info);
        }


        return 0;
    }
}
